/* This file contains configuration functions for the local DFS system */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <dfs.h>
#include <ctype.h>
#include "dfs_config.h"

/* * * * * * FILE RELATED FUNCTIONS * * * * * * */ 
											
/*     Configuring files & caches routine       */

int dfs_config_files(int action,const char *alias
							   ,char *data){
	int r;
	char filepath[PATH_MAX];
	
	memset(filepath,0,PATH_MAX);
	
	switch(action){
		case ACT_INDEXING:
			sprintf(filepath,"/home/%s",alias);
			r =dfs_add_file(filepath);
			return r;
			break;
		case ACT_REMOVING:
			r = dfs_remove_file(alias);
			return r;
			break;
		case ACT_FILES:
			r = dfs_list_files(data);
			return r;
			break;
		case ACT_FILEPATH:
			r = dfs_get_file_path(alias,data);
			return r;
			break;
		case ACT_CACHEGET:
			r = dfs_get_cache_path(alias,data);
			printf("config:%s\n",data);
			return r;
			break;
		default:
			return (OK);
	}
}


/* * * * * * NETWORKING RELATED FUNCTIONS * * * * * * */ 

/* 	   Configuring neighbours routine                 */

int dfs_config_neighbours(int action,const char *ip,int sd,char *data){
	switch(action){
		case ACT_CONNECTING:
			return dfs_set_neighbours_address(ip,sd);
			break;
	 	case ACT_NEIGHBOURS:
			return dfs_get_neighbours_list(data);
			break;
		case ACT_DISCONNECTING:
			return dfs_remove_neighbours_address(ip);
			break;
		default:
			return (OK);
	}
}
